#include "main.h" 

extern SDL_Event event;

//The surfaces
extern SDL_Surface *screen;
extern SDL_Surface *redGear;
extern SDL_Surface *greenGear;

extern void clean_up( Tile *tiles[] );

Gear::Gear() {}

Gear::Gear( bool type )
{
   box.x = GEAR_X_POS;
   box.y = GEAR_Y_POS;
   box.w = GEAR_WIDTH;
   box.h = GEAR_HEIGHT;
   
   gType = type;
   
   if (type)
      currentAlpha = SDL_ALPHA_OPAQUE;   
   else
      currentAlpha = SDL_ALPHA_TRANSPARENT;
}

void Gear::updateAlpha( float currTime, float timeLimit, bool col )
{
   if (gType)
   {
      /*//If a key was pressed
       if( event.type == SDL_KEYDOWN )
       {
           //Adjust the velocity
           switch( event.key.keysym.sym )
           {
               case SDLK_z: if( currentAlpha > SDL_ALPHA_TRANSPARENT ) currentAlpha -= 5; std::cout << gType << " pressed z! current alpha: " << currentAlpha << "\n" ; break;
               case SDLK_x: if( currentAlpha < SDL_ALPHA_OPAQUE ) currentAlpha += 5; std::cout << gType << " pressed x! current alpha: " << currentAlpha << "\n" ; break;
           }
       }
       //If a key was released
       else if( event.type == SDL_KEYUP )
       {
       
       }*/
            
       if (currentAlpha > SDL_ALPHA_TRANSPARENT)
              currentAlpha = SDL_ALPHA_OPAQUE - static_cast<int>(((currTime - timeLimit)/(-timeLimit)) * (-SDL_ALPHA_OPAQUE) + SDL_ALPHA_OPAQUE); 
       else
              currentAlpha = SDL_ALPHA_TRANSPARENT;
              
    }
}

void Gear::show()
{  
   if (gType)
   {
      SDL_SetAlpha(greenGear, SDL_SRCALPHA, currentAlpha);
      apply_surface( box.x, box.y, greenGear, screen, 0, 1 );
   }
   else
      apply_surface( box.x, box.y, redGear, screen, 0, 0 );
}

int Gear::getCurrentAlpha()
{
    return currentAlpha;
}
